//////////////////////////////////////////
//  File       	: adx.cpp               //
//  Written by	: ludmiloff@gmail.com	//
//  Copyright  	: GPL                   //
//////////////////////////////////////////

#ifndef __ADX_H
#define __ADX_H

#include <QSettings>
#include <IconTheme>
#include "defs.h"
#include "client.h"
#include "desktop.h"
#include "dockbar.h"
#include "panel.h"
#include "currentapp.h"
#include "screen.h"

#define MAJOR_VERSION 0
#define MINOR_VERSION 1
#define MODIFICATION "98-2"

class DBusAdaptor;
class QDBusInterface;
class AltTabDlg;

class Adx : public QApplication
{
	Q_OBJECT

public:
	enum AdxProcess {
		process_Initializing,
		process_Normal,
		process_MinimizingWindows,
		process_RestoringWindows,
		process_Wait,
		process_CreateWindow,
		process_SwitchingWindows,
	};
	
	Adx(int &argc, char **argv);
	~Adx();
	void wmCleanup();
	void readAdxSettings();

	// X11 event filter
	static bool x11_event_filter(void *message, long *result);

    // X11 error handler
    static int handleXError(Display *dpy, XErrorEvent *err);

    // X11 event management and helper routines
    void createTimeStampWindow();
    void createMyWindow(Window w);
	Client *getClientFromWindow(Window w);

    void createScreens();
    MyScreen *getScreenFromRoot(Window root);
    void grabServer();
    void ungrabServer();

	bool destroyWindow(XEvent *);
	bool unmapWindow(XEvent *);
	bool configureRequest(XEvent *);
	bool onFocusIn(XEvent *);
	bool onButtonPress(XEvent *);
	bool onHotKey(KeySym sym, uint mod);
	bool onKeyPress(XEvent *);
	bool onKeyRelease(XEvent *);
	void sendKeyEvent(XEvent *, long);
	bool onX11Property(XEvent *);
	bool colormapNotify(XEvent *);
	bool isSystemWidget(Window);
    void restack(Client *);
    void onAddTrayIcon(Window);
    void onRemoveTrayIcon(Window);

	// Window management routines
	void minimizeOthers(Client *);
	void minimizeAll();
	void showAll();
	void onDockIconRemoved(Client *);

public slots:
    void wmInit();
    void onAltTab();
	void focusTopmostClient();
	void manageRunningClients();
	void unmanageRunningClients();

public:
	// PC management routines
	void onLogout();
	void onPCSleep();
	void onPCRestart();
	void onPCShutdown();
	
	// Show Antico Deluxe "About this..." dialog
	void onAbout();
	
	// helper routines
	void setHighlightColor(const QColor &);
	void setMinimizeOnDblClick(bool);

	// mapped clients & decorations
    ClientList clients;
    ClientList decors;

	// internals
    //AmeIconTheme *iconTheme;
    Window sysId;                      // system widget/dialog Window id
    QList <MyScreen *> screens;
    int nscreens;
    Window timeStampWin;
    int xGrabCount;
	int m_Process;
	QObject obj;
	DBusAdaptor *WMCtrl;
	bool minimizeDblClick;
	QColor lastColor;
	QDBusInterface *hal;
    QSettings *stg;
	AltTabDlg *alttab;
	bool keygrab, ctrlgrab;
	Client *client;
    Display *dpy;
};

#endif
